/*
 * Application Name: 工作票信息管理系统
 * Desc: 自定义单例工具类
 * Author: Albert 
 * Date: 2009-08-08
 */
Ext.namespace('workpaper.ux');

workpaper.ux.ToolClass = Ext.extend(Object, {
	//用于工作票可编辑表格(已执行、已恢复)
	getEditorOfExecution : function(){
		return new Ext.form.ComboBox({
			typeAhead: true,
	    	forceSelection: true,
	    	editable: true,
	    	selectOnFocus:true,		
			triggerAction: 'all',
			store: [['\u0425','\u0425'],['\u221a','\u221a']],
			lazyRender: true,
			listClass: 'x-combo-list-small'
		})
	},
	
	//用于工作票可编辑表格(内容)
	getEditorOfContent : function(){
		return new Ext.form.ComboBox({
			typeAhead: true,
			triggerAction: 'all',
			store: [],
			lazyRender: true,
			listClass: 'x-combo-list-small'
		})
	},	
	
	//危险点与控制措施模板选择
	showDangersSelWin : function(){
        if(!this.winDangersSel){
		    this.dangersTree = new Ext.tree.TreePanel({
		    	layout:'fit',
		        id:'dangersSel-tree',
		        region:'west',
		        title:'危险点类别',
		        split:true,					
		        width: 150,
		        minSize: 90,
		        maxSize: 400,
		        collapsible: true,
		        margins:'0 0 5 5',
		        loader: new Ext.tree.TreeLoader({
			        url: '../../serverHTML/common/dangersModelType.html',
			        requestMethod: 'POST'
			    }),		    
				root: new Ext.tree.AsyncTreeNode({
				    id: 'root_dangers',
		            text: 'dangers',
		            expanded:true
				}),        
		        rootVisible:false,
		        lines:false,
		        autoScroll:true,
				tbar: [{							
						iconCls:'tree-expand',
						text:'展开',
						handler: function(){
							Ext.getCmp("dangersSel-tree").expandAll();								
						},
						scope: this
				},{							
						iconCls:'tree-collapse',
						text:'收缩',
						handler: function(){
							Ext.getCmp("dangersSel-tree").collapseAll();								
						},
						scope: this
				}]
		    });	 
		    
	    	this.dangersSelds = new workpaper.store.tools.dangersSelStore();	 
	    	this.dangersSelds.load();   	 	
	
		    this.dangersSelcm = new Ext.grid.ColumnModel([{
		           id: 'title',
		           header: "名 称",
		           dataIndex: 'title',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true
		        },{
		           id: 'creator',
		           header: "创建人",
		           dataIndex: 'creator',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true	           
		        },{
		           id: 'createTime',
		           header: "创建日期",
		           dataIndex: 'createTime',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true	           
		        }
		        ]);
		    this.dangersSelcm.defaultSortable = true;
		    
			this.dangersSelGrid =  new Ext.grid.GridPanel({            	
			    id:'dangersSelGrid',				        
			    activeTab:0,
			    region:'center',
			    title: '危险点与控制措施模板列表',
			    margins:'0 5 5 0',
			    split:true,
		        stripeRows:true,
		        columnLines : true,
		        autoWidth : true,
		        store: this.dangersSelds,
		        cm: this.dangersSelcm,        
		        viewConfig: {
		            forceFit:true,
		            enableRowBody:true,
		            showPreview:true
		        },
		        bbar: new Ext.PagingToolbar({	                		                	
		            pageSize: 25,
		            store: this.dangersSelds,
		            displayInfo: true	                    
		        })
			});		           	
        	
            this.winDangersSel = new Ext.Window({
            	id: 'winDangersSel',
            	modal: true,	                
                layout:'border',
                title: '危险点与控制措施模板选择',
                width:800,
                height:450,
                closeAction:'hide',
                plain: true,	
                items:[this.dangersTree,this.dangersSelGrid]
            });	            
        }
        
        this.winDangersSel.show(this);       	
	},
	
	//工作票模板选择
	showPaperModelSelWin : function(){
        if(!this.winPaperModelSel){
		    this.paperModelTree = new Ext.tree.TreePanel({
		    	layout:'fit',
		        id:'paperModelSel-tree',
		        region:'west',
		        title:'工作票类别',
		        split:true,					
		        width: 150,
		        minSize: 90,
		        maxSize: 400,
		        collapsible: true,
		        margins:'0 0 5 5',
		        loader: new Ext.tree.TreeLoader({
			        url: '../../serverHTML/common/paperModelType.html',
			        requestMethod: 'POST'
			    }),		    
				root: new Ext.tree.AsyncTreeNode({
				    id: 'root_paperModel',
		            text: 'paperModel',
		            expanded:true
				}),        
		        rootVisible:false,
		        lines:false,
		        autoScroll:true,
				tbar: [{							
						iconCls:'tree-expand',
						text:'展开',
						handler: function(){
							Ext.getCmp("paperModelSel-tree").expandAll();								
						},
						scope: this
				},{							
						iconCls:'tree-collapse',
						text:'收缩',
						handler: function(){
							Ext.getCmp("paperModelSel-tree").collapseAll();								
						},
						scope: this
				}]
		    });	 
		    
	    	this.paperModelSelds = new workpaper.store.tools.paperSelStore();	 
	    	this.paperModelSelds.load();   	 	
	
		    this.paperModelSelcm = new Ext.grid.ColumnModel([{
		           id: 'title',
		           header: "名 称",
		           dataIndex: 'title',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true
		        },{
		           id: 'creator',
		           header: "创建人",
		           dataIndex: 'creator',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true	           
		        },{
		           id: 'createTime',
		           header: "创建日期",
		           dataIndex: 'createTime',
		           width: 70,
		           align: 'center',
		           hidden: false,
		           sortable: true	           
		        }
		        ]);
		    this.paperModelSelcm.defaultSortable = true;
		    
			this.paperModelSelGrid =  new Ext.grid.GridPanel({            	
			    id:'paperModelSelGrid',
			    region:'center',
			    title: '工作票模板列表',
			    margins:'0 5 5 0',
			    split:true,
		        stripeRows:true,
		        columnLines : true,
		        autoWidth : true,
		        store: this.paperModelSelds,
		        cm: this.paperModelSelcm,        
		        viewConfig: {
		            forceFit:true,
		            enableRowBody:true,
		            showPreview:true
		        },
		        bbar: new Ext.PagingToolbar({	                		                	
		            pageSize: 25,
		            store: this.paperModelSelds,
		            displayInfo: true	                    
		        })
			});		           	
        	
            this.winPaperModelSel = new Ext.Window({
            	id: 'winpaperModelSel',	 
            	modal: true,               
                layout:'border',
                title: '工作票模板选择',
                width:800,
                height:450,
                closeAction:'hide',
                plain: true,	
                items:[this.paperModelTree,this.paperModelSelGrid]
            });	            
        }
        this.winPaperModelSel.show(this);       	
	},	
	
	//打印函数
	openPrinterWindow : function (contentid,winTitle){
		var para = "?contentid=" + contentid + "&title=" + escape(winTitle);
		var url = "paperPrinter.html" + para;
		window.open(url,"printer","height=768,width=1024,status=yes,toolbar=no,menubar=yes,location=no,resizable=yes,scrollbars=yes,left=0,top=0");
	},
	
	//创建新的FCKeditor实例，替换指定的Element并返回该实例
	createFCKeditorAndReplaceEl : function (elementId){
		var fckobj = new FCKeditor(elementId,675,600);  
		fckobj.BasePath = "../../extSDK/thirdPart/fckeditor/" ;  
		fckobj.ToolbarSet = 'Default' ;  
		fckobj.ReplaceTextarea();
		return fckobj;
	},	
	
	//获取unicode编码
	getUnicodeString : function(strSrc){
		var result = "";	
		for(var i = 0; i < strSrc.length; i++){
			var num = new Number(strSrc.charCodeAt(i));
			var hexStr = num.toString(16);
			var intLen = 4 - hexStr.length;		
			for(var j = 0; j < intLen; j++){
				hexStr = "0" + hexStr;
			}
			result = result + "\\u" + hexStr;
		}
		return result;
	}	
	
});

workpaper.ux.tools = new workpaper.ux.ToolClass();
